]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/keyboard: Ensure we always have at least one input source
authorRui Matos <tiagomatos@gmail.com>
Fri, 10 Oct 2014 13:54:30 +0000 (15:54 +0200)
committerRui Matos <tiagomatos@gmail.com>
Fri, 10 Oct 2014 16:45:45 +0000 (18:45 +0200)
Most of the code handles the sources setting being empty and
InputSourceManager.currentSource being null because previously the
"model" (i.e. the sources list) was kept in gnome-settings-daemon.

But this is fragile and since we're now the canonical place where the
list lives we can force it to never be empty even if the gsetting is
empty or contains only invalid entries.  Adding the default keyboard
layout in that case is the safest thing to do.

https://bugzilla.gnome.org/show_bug.cgi?id=738303

js/ui/status/keyboard.js

index 0c8454149114549b0c924ffcd51ce4e0fa8cdf32..8cb8cc913ca7c15592952613d6ba3249ce04f174 100644 (file)
@@ -298,8 +298,7 @@ const InputSourceManager = new Lang.Class({
         this._inputSources = {};
         this._ibusSources = {};
 
-        let inputSourcesByShortName = {};
-
+        let infosList = [];
         for (let i = 0; i < nSources; i++) {
             let displayName;
             let shortName;
@@ -323,11 +322,24 @@ const InputSourceManager = new Lang.Class({
                 }
             }
 
-            if (!exists)
-                continue;
+            if (exists)
+                infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
+        }
 
-            let is = new InputSource(type, id, displayName, shortName, i);
+        if (infosList.length == 0) {
+            let type = INPUT_SOURCE_TYPE_XKB;
+            let id = KeyboardManager.DEFAULT_LAYOUT;
+            let [ , displayName, shortName, , ] = this._xkbInfo.get_layout_info(id);
+            infosList.push({ type: type, id: id, displayName: displayName, shortName: shortName });
+        }
 
+        let inputSourcesByShortName = {};
+        for (let i = 0; i < infosList.length; i++) {
+            let is = new InputSource(infosList[i].type,
+                                     infosList[i].id,
+                                     infosList[i].displayName,
+                                     infosList[i].shortName,
+                                     i);
             is.connect('activate', Lang.bind(this, this._activateInputSource));
 
             if (!(is.shortName in inputSourcesByShortName))